package com.zhang.eightSorts;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Map;

/**
 * 选择排序，依旧是n^2的复杂度
 * 每次找出【后面】的最小值给替换
 */
public class SelectSort {


    SelectSort(int[] a)
    {
        for (int i=0;i<a.length-1;i++)
        {
            int minIndex=i;
            int min=a[i];

            for (int j=i+1;j<a.length;j++)
            {
                if (min>a[j])
                {
                    min=a[j];
                    minIndex=j;
                }
            }

            if (minIndex!=i)
            {
                a[minIndex]=a[i];
                a[i]=min;
            }
//            System.out.println("第"+(i+1)+"轮后~~");
//            System.out.println(Arrays.toString(a));
        }
    }
}
class Test{
    public static  void  main(String[] arg)
    {
        int[] arr=new int[80000];
        for (int i=0;i<arr.length;i++)
        {
            arr[i]=(int)(Math.random()*8000000);
        }
        int[] a=new  int[]{1,4,6,2,3,8};
        System.out.println(LocalDateTime.now());
        new SelectSort(arr);
        System.out.println(LocalDateTime.now());


    }

}